// 用Promise封装wx.request

const target = "http://127.0.0.1:3000"

// url格式: /路径
function request(obj){
  return new Promise((resolve,reject)=>{
    // console.log(obj)
    let {url,method,data,header} = obj

    // console.log(url,method,data,header)

    wx.request({
      url: target + url,
      method,
      data,
      header,
      timeout:5000,
      success(res){
        resolve(res.data)
      },
      fail(err){
        reject(err)
      }
    })
  })
}

export default request